package com.xinjiang.electricpower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils;
import com.xinjiang.electricpower.domain.DTO.WorkOrderPoolDTO;
import com.xinjiang.electricpower.domain.XjOrderGeneral;
import com.xinjiang.electricpower.domain.vo.AuthInfoVo;
import com.xinjiang.electricpower.domain.vo.WorkOrderPoolSummaryVO;
import com.xinjiang.electricpower.mapper.WorkOrderPoolMapper;
import com.xinjiang.electricpower.service.IUserAuthService;
import com.xinjiang.electricpower.service.IWorkOrderPoolService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author feizhao
 * @date 2022/11/11
 * @apiNote
 */
@Slf4j
@Service
public class WorkOrderPoolServiceImpl extends ServiceImpl<WorkOrderPoolMapper, XjOrderGeneral> implements IWorkOrderPoolService {

    @Autowired
    private IUserAuthService iUserAuthService;

    /**
     * 工单池按照各个类型汇总待办工单
     *
     * @return List<WorkOrderPoolSummaryVO> 返回汇总数据
     */
    @Override
    public List<WorkOrderPoolSummaryVO> getXjOrderGeneralByStatus(WorkOrderPoolDTO workOrderPoolDTO) {
        QueryWrapper<WorkOrderPoolSummaryVO> queryWrapper = new QueryWrapper<>();
        AuthInfoVo authStr = iUserAuthService.getAuthStr();
        queryWrapper.eq(StringUtils.isNotEmpty(authStr.getOrgNo()),"org_no",authStr.getOrgNo());
        queryWrapper.in(ObjectUtils.isNotEmpty(authStr.getConsNo()),"cons_no",authStr.getConsNo());
        queryWrapper.ge(ObjectUtils.isNotEmpty(workOrderPoolDTO.getBeginDateStart()), "CONVERT(begin_date,date)", workOrderPoolDTO.getBeginDateStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(workOrderPoolDTO.getBeginDateEnd()), "CONVERT(begin_date,date)", workOrderPoolDTO.getBeginDateEnd());
        queryWrapper.isNotNull("type");
        return baseMapper.selectXjOrderGeneralByStatus(queryWrapper);
    }
}
